<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%String skin = (String) session.getAttribute("USERSKIN_SESSION");%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">

<head>
    <meta charset="utf-8" />
    <!-- 卷/件管理 -->
    <title>山西省审计厅档案综合管理系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <jsp:include page="/inc/head.jsp" flush="true" />
    <link rel="stylesheet" href="${basePath}/assets/bootstrap_fileinput_master/css/fileinput.min.css" />
    <link href="${basePath}/css/webUpload/style.css" rel="stylesheet" />
    <link href="${basePath}/css/webUpload/demo.css" rel="stylesheet" />
    <link href="${basePath}/css/webUpload/webuploader.css" rel="stylesheet" />
    <link href="${basePath}/js/webuploader-0.1.5/webuploader.css" rel="stylesheet" />
    <style>
        .tablestyle td {
            height: 45px;
        }

        .tablestyle .content {
            padding: 0 11px;
            width: 80px;
        }

        .tablestyle .form-group {
            width: 120px;
        }

        .tablestyle select {
            width: 100%;
            height: 35px;
            border-radius: 3px;
            border-color: #aaa;
        }

        .tablestyle input {
            border: 1px solid #aaa;
            border-radius: 3px;
            width: 100%;
            height: 35px;
            padding-left: 5px;
        }

        .bootstrap-table .icon-refresh {
            padding: 3px 0;
        }
        #showAddressModal form .form-group>label {
            width: 100px;
            text-align: right;
        }
    </style>
</head>

<body>
    <div class="panel-body" style="padding-bottom:0px;">
        <div class="panel panel-default">
            <div class="panel-heading">查询条件</div>
            <div class="panel-body">
                <form id="formSearch" class="form-horizontal">
                    <div class="form-group" style="margin-top:15px">
                        <label class="control-label col-sm-1" for="sin_itemTitle">题名</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control" id="sin_itemTitle">
                        </div>
                        <label class="control-label col-sm-1" for="sin_itemType">档案类型</label>
                        <div class="col-sm-2">
                            <select id="sin_itemType" class="form-control" style="height: 34px;">
                            </select>
                        </div>
                        <div class="col-sm-3" style="text-align:left;">
                            <button type="button" style="margin-left:50px" id="btn_query" onclick="queryParamsSin()"
                                class="btn btn-primary">查询</button>
                            <button type="button" style="margin-left:20px" id="btn_clean"
                                onclick="queryParamsSinClean()" class="btn btn-default">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div id="toolbar" class="btn-group">
            <shiro:hasPermission name="cms:record:add"><button id="btn_add" type="button" class="btn btn-default"
                    onclick="detilsAction()">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 单件著录
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="cms:record:edit"><button id="btn_add" type="button" class="btn btn-default"
                    onclick="itemEditAction()">
                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 单件编辑
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="cms:record:delete"><button id="btn_delete" type="button" class="btn btn-default"
                    onclick="deleteAction()">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 删除
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="cms:record:import"><button id="btn_setting" type="button" class="btn btn-default"
                    onClick="importSettingAction()">
                    <span class="glyphicon glyphicon-import" aria-hidden="true"></span> 导入数据
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="cms:record:export">
                <%--<button id="btn_download" type="button" class="btn btn-default" onClick ="$('#table').tableExport({ type: 'excel', escape: 'false' })">--%>
                <button id="btn_download" type="button" class="btn btn-default" onClick="exportSinExcelAction()">
                    <span class="glyphicon glyphicon-export" aria-hidden="true"></span> 导出数据
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="cms:record:one"><button id="btn_mount" type="button" class="btn btn-default"
                    onClick="singleMountAction()">
                    <span class="glyphicon glyphicon-paperclip" aria-hidden="true"></span> 单件挂接
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="cms:record:mount"><button id="btn_mount" type="button" class="btn btn-default"
                    onClick="batchMountAction()">
                    <span class="glyphicon glyphicon-paperclip" aria-hidden="true"></span> 批量挂接
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="cms:record:archive"><button id="btn_submit" type="button" class="btn btn-default"
                    onclick="saveSingleArchiveAction()">
                    <span class="glyphicon glyphicon-flag" aria-hidden="true"></span> 归档
                </button>
            </shiro:hasPermission>
            <div class="btn-group">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                    归档状态<span class="caret"></span>
                </button>
                <ul class="dropdown-menu" role="menu">
                    <li><a id="notSubmit" onclick="SearchNotSubmitSin()" href="javascript:;">未归档</a></li>
                    <li><a id="turnDown" onclick="SearchTurnDownSin()" href="javascript:;">归档驳回</a></li>
                    <li><a id="failureSingle" onclick="FailureSin()" href="javascript:;">归档失败</a></li>
                </ul>
            </div>
        </div>

        <div id="showAddressModal" class="modal fade bs-example-modal-lg addUpdateInfo" role="dialog"
             aria-labelledby="myLargeModalLabel">
            <div class="modal-dialog " role="document">
                <div class="modal-content" style="width: 600px;">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="againAuditLabel">文件地址</h4>
                        <div class="modal-body" style="height: 400px;">

                            <form class="form radio" role="form" style="padding-left:10px;">
                                <div class="form-group">
                                    <label>选择地址：</label>
                                    <label class="radio-inline">
                                        <input type="radio" name="address"  id="address_1" value="1" checked> FTP地址
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" name="address" id="address_0" value="0"> 本地地址
                                    </label>
                                </div>

                                <div style="width:100%;" id="FTPtable">

                                    <div class="form-group">
                                        <label class="radio-inline">FTP IP：</label>
                                        <div class="form-group" style="display:inline-block;width:400px;">
                                            <input type='text' class="form-control" id="FTPIp" name="FTPIp"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="radio-inline">FTP 端口：</label>
                                        <div class="form-group" style="display:inline-block;width:400px;">
                                            <input type='text' class="form-control" id="FTPPort" name="FTPPort"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="radio-inline">FTP账号：</label>
                                        <div class="form-group" style="display:inline-block;width:400px;">
                                            <input type='text' class="form-control" id="FTPUser" name="FTPUser"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="radio-inline">FTP密码：</label>
                                        <div class="form-group" style="display:inline-block;width:400px;">
                                            <input type='text' class="form-control" id="FTPPassword" name="FTPPassword"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="radio-inline">FTP地址：</label>
                                        <div class="form-group" style="display:inline-block;width:400px;">
                                            <input type='text' class="form-control" id="FTPPath" name="FTPPath"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group"  style="width:100%;display:none;" id="addressDiv">
                                    <label class="radio-inline">本地地址：</label>
                                    <div class="form-group" style="display:inline-block;width:400px;">
                                        <input class="form-control" type='text' id="localAddress" name="localAddress"  value=''  />
                                    </div>
                                </div>
                            </form>
                            <%--

                            <div class="radio">
                                <div style="display: inline-block;height: 50px;width:100px;line-height: 50px;">
                                    <label for="address_1">FTP地址：</label>
                                    <input id="address_1" type="radio" name="address" value="1" style="margin-top:11px;" checked>
                                </div>
                                <div style="display: inline-block;height: 50px;width: 150px;line-height: 50px;margin-left:80px;">
                                    <label for="address_0">本地地址：</label>
                                    <input id="address_0" type="radio" name="address" value="0" style="margin-top:11px;">
                                </div>
                                <!-- 输入FTP信息 -->
                                <table style="width:100%;" id="FTPtable" >
                                    <tr>
                                        <td class="content" style="width: 120px;">
                                            FTP IP:
                                        </td>
                                        <td class="form-group">
                                            <input type='text' id="FTPIp" name="FTPIp"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="content" style="width: 120px;">
                                            FTP 端口:
                                        </td>
                                        <td class="form-group">
                                            <input type='text' id="FTPPort" name="FTPPort"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="content" style="width: 120px;">
                                            FTP账号:
                                        </td>
                                        <td class="form-group">
                                            <input type='text' id="FTPUser" name="FTPUser"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="content" style="width: 120px;">
                                            FTP密码:
                                        </td>
                                        <td class="form-group">
                                            <input type='text' id="FTPPassword" name="FTPPassword"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="content" style="width: 120px;">
                                            FTP地址:
                                        </td>
                                        <td class="form-group">
                                            <input type='text' id="FTPPath" name="FTPPath"/>
                                        </td>
                                    </tr>
                                </table>
                                <!-- 输入本地文件地址 -->
                                <div  style="width:100%;display:none;" id="addressDiv">
                                    <input  type='text' id="localAddress" name="localAddress"  value='' style="width:80%" />
                                </div>
                            </div>
                            --%>
                        </div>
                    </div>
                    <div class="modal-footer ">
                        <button type="button" class="btn green" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" id="createDefine" onclick="submitAddress(this);">确认</button>
                    </div>
                </div>
            </div>
        </div>

        <table id="table"></table>
        <!-- 记录著录与已驳回 -->
        <input type="hidden" id="sinStatus" value=0>
    </div>
    <jsp:include page="/inc/footer.jsp" flush="true" />
    <script src="${basePath}/js/devPublic.js"></script>
    <script src="${basePath}/assets/bootstrap_fileinput_master/js/fileinput.min.js"></script>
    <script src="${basePath}/assets/bootstrap_fileinput_master/js/locales/zh.js"></script>
    <jsp:include page="/WEB-INF/jsp/preArchive/batchMount.jsp" flush="true" />
    <script src="${basePath}/js/webuploader-0.1.5/webuploader.min.js"></script>
    <jsp:include page="/WEB-INF/jsp/preArchive/fileUpload.jsp" flush="true" />
    <jsp:include page="/WEB-INF/jsp/preArchive/viewOriginal.jsp" flush="true" />
    <jsp:include page="/WEB-INF/jsp/preArchive/singleImportSettingData.jsp" flush="true" />
    <jsp:include page="/WEB-INF/jsp/preArchive/singelAddItem.jsp" flush="true" />
    <jsp:include page="/WEB-INF/jsp/preArchive/singelEditItem.jsp" flush="true" />
    <jsp:include page="/WEB-INF/jsp/preArchive/carrierTypeSingle.jsp" flush="true" />

    </section>
    <script>
        var $table = $('#table');
        var columnsSin=[
            { field: 'ck', checkbox: true },
            {field: 'itemId', title: 'ID', visible:false},
            { field: 'itemNum', title: '保管期限', formatter: 'storageTimeSinFormatter' },
            { field: 'itemName', title: '文号' },
            { field: 'itemTemporary', title: '单元号', visible: false },
            { field: 'itemSecret', title: '密级', formatter: 'secretLevelFormatter', visible: false },
            { field: 'itemExp4', title: '保密年限', visible: false },
            { field: 'itemExp1', title: '文件类型', formatter: 'typeSingleItemFormatter' },
            { field: 'itemExp2', title: '归档单位', formatter: 'orgIdConversionNameFormatter' },
            { field: 'itemExp3', title: '归档年度',sortable: true },
            { field: 'itemTitle', title: '题名' },
            { field: 'itemRespons', title: '责任者' },
            { field: 'itemCreateTime', title: '发文日期' },
            { field: 'itemFian', title: '全宗号' },
            { field: 'itemStr1', title: '件号'},
            { field: 'itemStr4', title: '著录人', visible: false },
            { field: 'itemArcPerson', title: '归档责任人', visible: false },
            { field: 'itemStr1Date', title: '归档日期', formatter: 'createItemAction', visible: false },
            { field: 'itemPage', title: '页数', visible: false },
            { field: 'itemPublicStatus', title: '是否公开', visible: false,formatter: 'publicStatusFormatter' },
            { field: 'itemCarrier', title: '载体类型',formatter: 'carrierStatusFormatter' },
            { field: 'itemNote', title: '备注', visible: false },
            { field: 'itemStr3', title: '挂接状态', formatter: 'statusFormatter' ,align:"center"},
            { field: 'itemArcStatus', title: '文件状态', formatter: 'statusSingleItemFormatter' },
            { field: 'itemCreateDate', title: '创建时间', formatter: 'createItemAction', visible: false },
            { field: 'action', title: '操作', align: 'center', formatter: 'actionFormatter', events: 'actionEvents', clickToSelect: false }
        ];

        $(function () {
            var urlSin='${basePath}/pcwindow/sin/itemSinList';
            bootstrapTableAction(urlSin,columnsSin);
            $("#btn_submit").show();
            findAllJudTypeSiN(1);

            //根据单选结果获取输入地址内容
            $(".radio").find(":radio").change(function(){
                var address = $(this).val();
                //如果是本地地址
                if(address==0){
                    $("#addressDiv").show();
                    $("#FTPtable").hide();
                }else{
                    $("#FTPtable").show();
                    $("#addressDiv").hide();
                }
            })
        })
        function bootstrapTableAction(url,columns) {
            $table.bootstrapTable({
                url: url,//请求后台的URL（*）
                method: 'get',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: true,                     //是否启用排序
                sortOrder: "desc",                   //排序方式
                //queryParams: queryParams,//传递参数（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 500,                       //每页的记录行数（*）
                pageList: [200,500,1000],        //可供选择的每页的行数（*）
                //search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                //strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                //height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                //showToggle:true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns:columns,
                onLoadSuccess:function(data){
                    //无数据隐藏分页
                    if(data && data.total == 0){
                        $('.fixed-table-pagination').css('display','none')
                    }
                }
            });
        };

        //格式化保管期限
        function storageTimeSinFormatter(value, row, index) {
            return storageTime[value];
        }
        //格式化密级
        function secretLevelFormatter(value, row, index) {
            return secretLevel[value];
        }
        //格式化归档单位
        function orgIdConversionNameFormatter(value, row, index) {
            return orgList[value];
        }

        //文件类型转换
        function typeSingleItemFormatter(value, row, index) {
            // alert(archiveType[value]);
            return archiveType[value];
        };

        // 格式化状态
        function statusFormatter(value, row, index) {
            if (row.itemCarrier == '0') {
                return '<span class="label label-default">-</span>';
            }else{
                if (value == '1') {
                    return '<span class="label label-success">已上传</span>';
                } else {
                    return '<span class="label label-info">未上传</span>';
                }
            }
        }
        //格式化归档状态
        function statusSingleItemFormatter(value, row, index) {
            if (value == '0') {
                return '<span class="label label-default">新著录</span>';
            } else if (value == '1') {
                return '<span class="label label-success">已归档</span>';
            } else if (value == '2') {
                return '<span class="label label-info">已驳回</span>';
            }else if (value == '3') {
                return '<span class="label label-warning">归档失败</span>';
            } else {
                return '<span class="label label-danger">未知</span>';
            }
        }
        //是否公开
        function publicStatusFormatter(value, row, index){
            if (value == '0') {
                return '<span class="label label-warning">未公开</span>';
            } else{
                return '<span class="label label-info">公开</span>';
            }
        }
        //载体类型
        function carrierStatusFormatter(value, row, index) {
            if (value == '0') {
                return '<span class="label label-warning">仅实体</span>';
            } else if(value == '1'){
                return '<span class="label label-info">仅电子</span>';
            }else {
                return '<span class="label label-success">共存</span>';
            }
        }

        /**
         *	操作按钮
         */
        function actionFormatter(value, row, index) {
            if (row.itemCarrier == '0') {
                return '<a href="javascript:void(0)" style="color:#01579b;" onclick="singleMountTableAction(' + row.itemId+')" >挂接</a>';
            }else{
                if(row.itemStr3=="0"||row.itemStr3==0){
                    return '<a href="javascript:void(0)" style="color:#01579b;" onclick="singleMountTableAction(' + row.itemId+')" >挂接原文</a>';
                }else {
                    return '<a href="javascript:void(0)" style="color:#01579b;" onclick="detailAction(' + row.itemId + ')" >查看原文</a>';
                }
            }
        }

        /**
         * 跳转原文页面
         */
        function detailAction(itemId) {
            if (itemId != "" && itemId != null) {
                $.ajax({
                    type: "post",
                    url: "${basePath}/pcwindow/sin/viewSinItemOriginal",
                    data: { itemId: itemId },
                    success: function (data) {
                        if (data != "failure") {
                            $('#openPdfModel').modal({
                                keyboard: true
                            });
                            var url = data;
                            var str = url.substr(url.length - 4, url.length - 1);
                            if (str == ".jpg" || str == ".png") {
                                var htmlImg = '<img src="' + url + '" style=" width:100%;height: 100%;" alt="预览">';
                                $("#pdfDialog").eq(0).append(htmlImg);
                            } else {
                                var options = {
                                    pdfOpenParams: {
                                        pagemode: "thumbs",
                                        navpanes: '0',
                                        //toolbar: '0',   //去掉工具栏,打印,下载等,,,,
                                        statusbar: '0',
                                        view: 'FitV'
                                    }
                                };
                                var myPDF = PDFObject.embed(url, "#pdfDialog", options);
                            }
                        } else {
                            confirmEvent("获取原文失败!");
                        }
                    },
                    error: function () {
                        confirmEvent('加载错误,请联系管理员!');
                    }
                })
            } else {
                confirmEvent('请选择数据!');
            }
        }

        /**
         * 重置查询条件
         */
        function queryParamsSinClean() {
            $("#sin_itemTitle").val("");
            $("#sin_itemType").empty();
            findAllJudTypeSiN(1);
        }

        /**
         * 条件查询
         */
        function queryParamsSin() {
            var queryPa = {
                sin_itemTitle: $("#sin_itemTitle").val(),
                sin_itemType: $("#sin_itemType").find(":selected").val(),
                sinStatus: $("#sinStatus").val()
            };
            var opt = {
                url: '${basePath}/pcwindow/sin/itemSinList',
                silent: true,
                query: queryPa
            };
            $table.bootstrapTable('refresh', opt);
        }
        //查询已驳回
        function SearchTurnDownSin() {
            $("#btn_submit").show();
           /* var opt = {
                url: "/pcwindow/sin/itemSinList?sinStatus=" + 2,
                silent: true,
                pageNumber: 1
            };
            $table.bootstrapTable('refreshOptions', opt);*/
            $("#sinStatus").val(2);
            $table.bootstrapTable('destroy');
            var urlSin="${basePath}/pcwindow/sin/itemSinList?sinStatus=" + 2;
            bootstrapTableAction(urlSin,columnsSin);
        }

        //未归档(著录)
        function SearchNotSubmitSin() {
            $("#btn_submit").show();
           /* var opt = {
                url: "/pcwindow/sin/itemSinList?sinStatus=" + 0,
                silent: true,
                pageNumber: 1
            };
            $table.bootstrapTable('refreshOptions', opt);*/
            $("#sinStatus").val(0);
            $table.bootstrapTable('destroy');
            var urlSin="${basePath}/pcwindow/sin/itemSinList?sinStatus=" + 0;
            bootstrapTableAction(urlSin,columnsSin);
        }

        //归档失败
        function FailureSin() {
            $("#btn_submit").hide();
            $table.bootstrapTable('destroy');
            var failureUrlSin="${basePath}/pcwindow/sin/itemSinList?sinStatus=" + 3;
            var failureColumnsSin=[
                { field: 'ck', checkbox: true },
                { field: 'itemStr1', title: '原件号' },
                { field: 'itemExp6', title: '系统生成件号' },
                { field: 'itemExp5', title: '归档错误原因' ,formatter: 'failureErrorReasonSinItemFormatter'},
                { field: 'itemNum', title: '保管期限', formatter: 'storageTimeSinFormatter' },
                { field: 'itemName', title: '文号' , visible: false},
                { field: 'itemTemporary', title: '单元号', visible: false },
                { field: 'itemSecret', title: '密级', formatter: 'secretLevelFormatter', visible: false },
                { field: 'itemExp4', title: '保密年限', visible: false },
                { field: 'itemExp1', title: '文件类型', formatter: 'typeSingleItemFormatter' },
                { field: 'itemExp2', title: '归档单位', formatter: 'orgIdConversionNameFormatter' },
                { field: 'itemExp3', title: '归档年度' },
                { field: 'itemTitle', title: '题名' },
                { field: 'itemRespons', title: '责任者' },
                { field: 'itemCreateTime', title: '发文日期' , visible: false},
                { field: 'itemFian', title: '全宗号' },
                { field: 'itemStr4', title: '著录人', visible: false },
                { field: 'itemArcPerson', title: '归档责任人', visible: false },
                { field: 'itemStr1Date', title: '归档日期', formatter: 'createItemAction', visible: false },
                { field: 'itemPage', title: '页数', visible: false },
                { field: 'itemPublicStatus', title: '是否公开', visible: false,formatter: 'publicStatusFormatter' },
                { field: 'itemCarrier', title: '载体类型', visible: false,formatter: 'carrierStatusFormatter' },
                { field: 'itemNote', title: '备注', visible: false },
                { field: 'itemStr3', title: '挂接状态', formatter: 'statusFormatter',align:"center" },
                { field: 'itemArcStatus', title: '文件状态', formatter: 'statusSingleItemFormatter' },
                { field: 'itemCreateDate', title: '创建时间', formatter: 'createItemAction', visible: false },
                { field: 'action', title: '操作', align: 'center', formatter: 'sinItemErrorAction', events: 'actionEvents', clickToSelect: false }
            ];
            bootstrapTableAction(failureUrlSin,failureColumnsSin);
            $("#sinStatus").val(3);
        }

        /**
         * 归档失败操作按钮
         */
        function sinItemErrorAction(value, row, index){
            var itemArcStatus = row.itemArcStatus;
            var itemExp5 = row.itemExp5;
            if( itemArcStatus== "3" && itemExp5=="4"){
                return '<a href="javascript:void(0)" style="color:red;" onclick="beforeSinItemErrorAction(' + row.itemId+')" title="请核对无误后进行">原件号强制归档</a>&nbsp;&nbsp;'+
                    '&nbsp;&nbsp;<a href="javascript:void(0)" style="color:green;" onclick="nowSinItemErroErrordetailAction(' + row.itemId+')" title="请核对无误后进行">归档</a>';
            }else{
                return '<a href="javascript:void(0)" style="color:green;" onclick="nowSinItemErroErrordetailAction(' + row.itemId+')" title="卷内件的件号不跟随变动">归档</a>&nbsp;&nbsp;'
            }
        }
        /**
         * 使用系统档号归档
         */
        function nowSinItemErroErrordetailAction(sinItemId){
            $.ajax({
                type: "post",
                url: "${basePath}/pcwindow/sinItemErrorArchive",
                data: { sinItemId: sinItemId,sinArchiveStatus:"1"},
                success: function (data) {
                    if (data == "success") {
                        $table.bootstrapTable('refresh');
                        confirmEvent("确定成功!");
                    }else {
                        confirmEvent(data);
                    }
                }
            })
        }

        /**
         * 原件号强制归档
         */
        function beforeSinItemErrorAction(sinItemId){
            $.ajax({
                type: "post",
                url: "${basePath}/pcwindow/sinItemErrorArchive",
                data: { sinItemId: sinItemId,sinArchiveStatus:"0"},
                success: function (data) {
                    if (data == "success") {
                        $table.bootstrapTable('refresh');
                        confirmEvent("确定成功!");
                    }else {
                        confirmEvent(data);
                    }
                }
            })
        }

        /**
         * 归档错误原因
         */
        function failureErrorReasonSinItemFormatter(value, row, index){
            if (value == '1') {
                return '<span style="color: red">未挂接原文</span>';
            }else if(value == '2'){
                return '<span style="color: red">构成件号的著录项为空</span>';
            }else if(value == '3'){
                return '<span style="color: red">载体类型为空</span>';
            }else if(value == '4'){
                return '<span style="color: red">件号比对失败</span>';
            }else {
                return '<span style="color: red">未知，请核对著录项</span>';
            }
        }

        /**
         * 件时间处理
         */
        function createItemAction(value, row, index) {
            var timeItem = value;
            if(timeItem=="" || timeItem=="null" || timeItem==null){
                return "";
            }else {
                return formatshortDateTime(timeItem);

            }
        }

        /**
         * 删除数据
         */
        function deleteAction() {
            var rows = $table.bootstrapTable('getSelections');
            if (rows.length != 0) {
                Ewin.confirm({ message: "确认要删除选择的数据吗？" }).on(function (e) {
                    if (!e) {
                        return;
                    }
                    var idsSin = new Array();
                    for (var i in rows) {
                        idsSin.push(rows[i].itemId);
                    }
                    $.ajax({
                        type: "post",
                        url: "${basePath}/pcwindow/sin/deleteSin",
                        data: { idsSin: idsSin.join("-") },
                        success: function (data) {
                            if (data == "success") {
                                $table.bootstrapTable('refresh');
                            } else {
                                confirmEvent(data);
                            }
                        },
                        error: function () {
                            confirmEvent('删除错误,请联系管理员!');
                        }
                    })
                });
            } else {
                confirmEvent("请选择要删除的数据!");
            }
        }

        /**
         * 单件著录Model开启
         */
        function detilsAction() {
            $('#singelAddItemModel').modal({
                keyboard: true
            });

            //加载全宗号
            loadAllArcNumberActionSIN();
            //加载所有案卷类型
            findAllJudTypeSiN();
            //加载保管期限
            findAllStorageTimeSin();
            //加载密级
            findAllsecretLevelSin();
            //加载组织机构
            initSelectarcApartment();
        }

        /**
         * 单件编辑Model开启
         */
        function itemEditAction() {
            var rows = $table.bootstrapTable('getSelections');
            if (rows.length == 1) {
                $.ajax({
                    type: "post",
                    url: "${basePath}/pcwindow/sin/edit",
                    data: { idEdit: rows[0].itemId },
                    success: function (data) {
                        $("#editSinForm")[0].reset();
                        $("itemPublicStatus").find("option:selected").prop("selected",false);
                        $("itemCarrier").find("option:selected").prop("selected",false);
                        if (data.code == 1) {
                            //加载所有案卷类型
                            findAllJudTypeEditSiN();
                            //加载保管期限
                            findAllStorageTimeSinEdit();
                            //加载密级
                            findAllsecretLevelSinEdit();
                            //加载组织机构
                            initSelectarcApartmentEdit();

                            var eval2 = eval('(' + data.data + ')');
                            $('#itemIdEdit').val(eval2.itemId);
                            $('#itemExp1Edit').val(eval2.itemExp1);
                            var itemNum = eval2.itemNum;
                            $("#itemNumEdit").val(itemNum);
                            //$("#itemNumEdit").find("option[text='"+itemNum+"']").attr("selected",true);
                            $("#itemFianEdit").val(eval2.itemFian);
                            $("#itemExp3Edit").val(eval2.itemExp3);
                            $("#itemExp2Edit").val(eval2.itemExp2);

                            $("#itemSecretEdit").val(eval2.itemSecret);
                            var itemExp4 = eval2.itemExp4;
                            $("#itemExp4Edit").val(itemExp4);

                            $("#itemTemporaryEdit").val(eval2.itemTemporary);
                            $("#itemCreateTimeEdit").val(eval2.itemCreateTime);
                            $("#itemTitleEdit").val(eval2.itemTitle);
                            $("#itemNameEdit").val(eval2.itemName);
                            $("#itemResponsEdit").val(eval2.itemRespons);
                            $("#itemPageEdit").val(eval2.itemPage);
                           // $("#itemPublicStatus").val(eval2.itemPublicStatus);
                            $("#itemPublicStatus option[value='"+eval2.itemPublicStatus+"']").prop("selected",true);
                           // $("#itemCarrier").val(eval2.itemCarrier);
                            $("#itemCarrier option[value='"+eval2.itemCarrier+"']").prop("selected",true);

                            $('#singelEditItemModel').modal({
                                keyboard: true
                            });
                        } else {
                            confirmEvent("数据查询错误!");
                        }
                    },
                    error: function () {
                        confirmEvent('操作错误,请联系管理员!');
                    }
                })
            } else {
                confirmEvent('请选中一条单件数据!');
            }


        }

        /**
         * 载体类型选择跳转
         */
       /* function submitSinItemAction() {
            $('#carrierTypeSingleDialog').modal({
                keyboard: true
            });
        }*/

        /**
         * 归档提交
         */
        function saveSingleArchiveAction() {
            var rows = $table.bootstrapTable('getSelections');
            if (rows.length != 0) {
                //var itemCarrierValue = $("input[name='itemCarrier']:checked").val();

                var idsSinOne = new Array();
                for (var i in rows) {
                    idsSinOne.push(rows[i].itemId);
                }
                $.ajax({
                    type: "post",
                    url: "${basePath}/pcwindow/sin/submitSinItem",
                    //data: { idsSinOne: idsSinOne.join("-"), itemCarrierValue: itemCarrierValue },
                    data: { idsSinOne: idsSinOne.join("-")},
                    success: function (data) {
                        if (data == "success") {
                            confirmEvent("归档成功!");
                        } else {
                            confirmEvent(data);
                        }
                        $table.bootstrapTable('refresh');
                    }
                })
            } else {
                confirmEvent('请选中一行数据!');
            }
        }

        /**
         * 上传数据及设置
         */
        function importSettingAction() {
            $('#openSingeleImportSettingDataModel').modal({
                keyboard: true
            });
            dataBaseAppendAction();
        }

        /**
         * 单个挂接
         */
        function onlyOneAction() {
            var rowsOnly = $table.bootstrapTable('getSelections');
            var lengthOnly = rows.length;
            var volIdOnly = [];
            if (length == 0) {
                confirmEvent('仅可选择一条数据!');
            } else {

                confirmEvent("对接单件挂接");
            }
        }

        /**
         * 批量挂接
         */
        function batchMountAction() {
            var rows = $table.bootstrapTable('getSelections');
            var length = rows.length;
            var volId = [];
            if (length == 0) {
                confirmEvent('请至少选择一条数据!');
            } else {
                Ewin.confirm({ message: "本地或FTP地址方式上传（确定）,选择文件上传(取消)" }).on(function(e){
                    if(!e){
                        for (var index in rows) {
                            var row = rows[index];
                            var itemId = row.itemId;
                            var itemStatus = row.itemStr3;
//                    if (itemStatus == 1) {
//                        confirmEvent('当前挂接文件中 存在已经挂接的文件!');
//                        return;
//                    } else {
//                        volId.push(itemId);
//                    }
                            volId.push(itemId);
                        }
                        $("#uploadSubmit").attr("data-id", volId.join(","));
                        $("#uploadSubmit").attr("data-type", 2);
                        $("#uploadSubmit").attr("data-fileNum", 2);
                        $("#uploadSubmit").attr("data-tableId", "table");
                        // 加载addmodel
                        $('#showUploadModal').modal({
                            keyboard: true
                        });
                    }else{
                        $("#FTPtable").find("input").val("");
                        $("#addressDiv").find("input").val("");
                        //加载addmodel
                        $('#showAddressModal').modal({
                            keyboard: true
                        });
                    }
                })
            }
        }

        //挂接原文(单件挂接，在Table中直接操作)
        function singleMountTableAction(itemId){
            $("#uploadSubmit").attr("data-id", itemId);
            $("#uploadSubmit").attr("data-type", 2);
            $("#uploadSubmit").attr("data-fileNum", 1);
            $("#uploadSubmit").attr("data-tableId", "table");
            // 加载addmodel
            $('#showUploadModal').modal({
                keyboard: true
            });
        }

        //单件挂接
        function singleMountAction() {
            var rows = $table.bootstrapTable('getSelections');
            var length = rows.length;
            if (length != 1) {
                confirmEvent('请仅且选择一条数据!');
            } else {
                var row = rows[0];
                var itemId = row.itemId;
//                var itemStatus = row.itemStr3;
//                if (itemStatus == 1) {
//                    confirmEvent('当前挂接文件 已经挂接了文件!');
//                    return;
//                }
                $("#uploadSubmit").attr("data-id", itemId);
                $("#uploadSubmit").attr("data-type", 2);
                $("#uploadSubmit").attr("data-fileNum", 1);
                $("#uploadSubmit").attr("data-tableId", "table");
                // 加载addmodel
                $('#showUploadModal').modal({
                    keyboard: true
                });
            }
        }

        /**
         * 单件导出数据
         */
        function exportSinExcelAction() {
            var sin_itemTitle = $("#sin_itemTitle").val();
            var sin_itemType = $("#sin_itemType").find(":selected").val();
            var sinStatus = $("#sinStatus").val();
            window.location.href = "${basePath}/pcwindow/exportSinDataExcel?sin_itemTitle="
                + sin_itemTitle + "&sin_itemType=" + sin_itemType + "&sinStatus=" + sinStatus;
        }


        //提交地址信息
        function submitAddress(event) {
            $(event).attr("disabled",true);
            var rows = $table.bootstrapTable('getSelections');
            var volIds = [];
            for(var index = 0;index<rows.length;index++){
                volIds.push(rows[index].itemId);
            }
            var isFtpOrAdr = $(".radio").find(":checked").val();
            console.log(isFtpOrAdr);
            var formData = new FormData();
            //如果为0，为本地地址
            if(isFtpOrAdr==0){
                formData.append("FTPIp","");
                var localAddress = $("#localAddress").val();
                console.log(localAddress);
                if(localAddress==""){
                    confirmEvent("请填写地址!");
                    $(event).attr("disabled",false);
                    return;
                }
            }else{
                var FTPIp = $("#FTPIp").val();
                var FTPPassword = $("#FTPPassword").val();
                var FTPPort = $("#FTPPort").val();
                var FTPPath = $("#FTPPath").val();
                var FTPUser = $("#FTPUser").val();
                if(FTPIp==''&&FTPPort==""&&FTPPath==""){
                    confirmEvent("请将ftp信息填写完整!");
                    $(event).attr("disabled",false);
                    return;
                }
                formData.append("FTPIp",$("#FTPIp").val());
            }
            formData.append("FTPUser",$("#FTPUser").val());
            formData.append("FTPPort",$("#FTPPort").val());
            formData.append("FTPPassword",$("#FTPPassword").val());
            formData.append("FTPPath",$("#FTPPath").val());
            formData.append("localAddress",$("#localAddress").val());
            formData.append("volIds",volIds.join(","));
            formData.append("type","2");
            $.ajax({
                url:'${basePath}/pcwindow/uploadByAddress',
                type:"post",
                data:formData,
                dataType:"json",
                processData: false,  //tell jQuery not to process the data
                contentType: false,  //tell jQuery not to set contentType
                success:function (data) {
                    var status = data.code;
                    if(status==0){
                        confirmEvent(data.message);
                        $(event).attr("disabled",false);
                        $("#showAddressModal").modal("hide");
                    }else{
                        confirmEvent(data.message);
                        $(event).attr("disabled",false);
                        $("#showAddressModal").modal("hide");
                    }
                }
            })
        }

    </script>
</body>

</html>